home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / c-include / egsgadbox.h < prev    next >
C/C++ Source or Header  |  1994-06-06  |  15KB  |  394 lines

  1. #ifndef EGS_EGSGADBOX_H
  2. #define EGS_EGSGADBOX_H
  3.  
  4. /***************************************************************************\
  5. *  $
  6. *  $ FILE     : egsgadbox.h
  7. *  $ VERSION  : 1
  8. *  $ REVISION : 4
  9. *  $ DATE     : 07-Feb-93 18:05
  10. *  $
  11. *  $ Author   : mvk
  12. *  $
  13. *
  14. ****************************************************************************
  15. *                                                                          *
  16. * (c) Copyright 1990/93 VIONA Development                                  *
  17. *     All Rights Reserved                                                  *
  18. *                                                                          *
  19. \***************************************************************************/
  20.  
  21. #ifndef         EXEC_TYPES_H
  22. #include        <exec/types.h>
  23. #endif
  24. #ifndef         EGS_EGSGFX_H
  25. #include        <egs/egsgfx.h>
  26. #endif
  27. #ifndef         EGS_EGSINTUI_H
  28. #include        <egs/egsintui.h>
  29. #endif
  30. #ifndef         EGS_EGSINTUIGFX_H
  31. #include        <egs/egsintuigfx.h>
  32. #endif
  33.  
  34. /*
  35.  * The egsgadbox.library is the basic library for font sensitive and resizeable
  36.  * gadgets/requesters. The programmer defines the shape of a requester by
  37.  * a recursive structure of boxes, a gadget box tree. The elements of this tree
  38.  * can be gadgets, rendering routines or ordering boxes, that contain several
  39.  * other boxes and order them in a given way. From this tree a list of gadgets
  40.  * and a rendering programm for additional graphics is calculated.
  41.  *
  42.  * The elements of this tree are generated using the function of this library,
  43.  * and linked together by two functions. Lower elements in the tree serve as
  44.  * additional graphics or gadgets for higher elements or gadgets. By the usage
  45.  * of fillboxes and borderboxes, the elements can be grouped and separated.
  46.  *
  47.  * Example for a color modification gadget, using three scrollers with arrows
  48.  *
  49.  * Treestructure:
  50.  *
  51.  * unknown, gadget : Master gadget for the requester
  52.  * | horizontal, draw : Rectangle surrounding
  53.  * | | unknown, - : horizontal fill box
  54.  * | | vertical, - : grouping for the first prop gadget
  55.  * | | | unknwon, gadget : upper arrow gadget, first scroller
  56.  * | | | | horizontal, draw : Rectangle surrounding the arrow
  57.  * | | | | | unknown, - : horizontal fill box
  58.  * | | | | | vertical, - :
  59.  * | | | | | | unknown, - : vertical fill box
  60.  * | | | | | | unknown, draw : dynamic rendering of an arrow
  61.  * | | | | | | unknown, - : vertical fill box
  62.  * | | | | | unknown, - : horizontal fill box
  63.  * | | | unknwon, gadget : scroller gadget, including its rendering
  64.  * | | | unknwon, gadget : lower arrow gadget, first scroller
  65.  * | | | | horizontal, draw : Rectangle surrounding the arrow
  66.  * | | | | | unknown, - : horizontal fill box
  67.  * | | | | | vertical, - :
  68.  * | | | | | | unknown, - : vertical fill box
  69.  * | | | | | | unknown, draw : dynamic rendering of an arrow
  70.  * | | | | | | unknown, - : vertical fill box
  71.  * | | | | | unknown, - : horizontal fill box
  72.  * | | unknown, - : horizontal fill box
  73.  * | | vertical, - : grouping for the second prop gadget
  74.  * | | | unknwon, gadget : upper arrow gadget, secode scroller
  75.  * | | | | horizontal, draw : Rectangle surrounding the arrow
  76.  * | | | | | unknown, - : horizontal fill box
  77.  * | | | | | vertical, - :
  78.  * | | | | | | unknown, - : vertical fill box
  79.  * | | | | | | unknown, draw : dynamic rendering of an arrow
  80.  * | | | | | | unknown, - : vertical fill box
  81.  * | | | | | unknown, - : horizontal fill box
  82.  * | | | unknwon, gadget : scroller gadget, including its rendering
  83.  * | | | unknwon, gadget : lower arrow gadget, first scroller
  84.  * | | | | horizontal, draw : Rectangle surrounding the arrow
  85.  * | | | | | unknown, - : horizontal fill box
  86.  * | | | | | vertical, - :
  87.  * | | | | | | unknown, - : vertical fill box
  88.  * | | | | | | unknown, draw : dynamic rendering of an arrow
  89.  * | | | | | | unknown, - : vertical fill box
  90.  * | | | | | unknown, - : horizontal fill box
  91.  *
  92.  *   ...
  93.  *
  94.  *
  95.  * Assuming con contains a valid EB_GadContext, and b1 and b2 are EB_GadBoxPtr,
  96.  * this structure can be created by:
  97.  *
  98.  b1 = EB_CreateHorizBox(con);
  99.  EB_AddLastSon(b1,EB_CreateHorizFill(con,0,0));
  100.  EB_AddLastSon(b1,EB_CreateSuperVertiProp(con,255,16,0,$1000,
  101.                       EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT));
  102.  EB_AddLastSon(b1,EB_CreateHorizFill(con,0,0));
  103.  EB_AddLastSon(b1,EB_CreateSuperVertiProp(con,255,16,0,$1001,
  104.                       EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT));
  105.  EB_AddLastSon(b1,EB_CreateHorizFill(con,0,0));
  106.  EB_AddLastSon(b1,EB_CreateSuperVertiProp(con,255,16,0,$1002,
  107.                       EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT));
  108.  EB_AddLastSon(b1,EB_CreateHorizFill(con,0,0));
  109.  root = EB_CreateMaster(con,$4711,$1010);
  110.  EB_AddLastSon(root, EB_CreateFrontBorder(con, b1, EB_FILL_ALL));
  111.  *
  112.  * From this gadget tree a list of gadgets and a rendering programm can be
  113.  * calculated using EB_ProcessGadBoxes.
  114.  *
  115.  */
  116.  
  117. /*
  118.  * EB_ContextPtr
  119.  *
  120.  * Pointer to a structure that keeps track of allocated memory. This is used
  121.  * to allocate the memory for the temporary tree, and permanent gadgets.
  122.  */
  123.  
  124. typedef APTR EB_ContextPtr;
  125.  
  126. typedef struct EB_GadBox *EB_GadBoxPtr;
  127.  
  128. /*
  129.  * EB_ResBox
  130.  *
  131.  * The library uses this structure to return locations and sizes of custom
  132.  * boxes in the created requester/window. A pointer to this structure is
  133.  * passed to EB_CreateResponseBox.
  134.  */
  135. typedef struct EB_ResBox *EB_ResBoxPtr;
  136.  
  137. struct EB_ResBox { WORD X, Y, W, H; };
  138.  
  139. /*
  140.  * EB_InfoBox
  141.  *
  142.  * Extension to the EB_ResBox structure, for changing textuell information
  143.  */
  144. typedef struct EB_InfoBox *EB_InfoBoxPtr;
  145.  
  146. struct EB_InfoBox {
  147.      EG_EFontPtr       Font;
  148.      UBYTE             Justify;
  149.      UBYTE             Pad;
  150.      struct EB_ResBox  Box;
  151. };
  152.  
  153. /*
  154.  * Fill flags, needed at several locations, to determine on which sides
  155.  * further filling is recommended or posible.
  156.  */
  157. #define EB_FILL_LEFT   1
  158. #define EB_FILL_RIGHT  2
  159. #define EB_FILL_TOP    4
  160. #define EB_FILL_BOTTOM 8
  161. #define EB_FILL_ALL    (EB_FILL_LEFT|EB_FILL_RIGHT|EB_FILL_TOP|EB_FILL_BOTTOM)
  162.  
  163. /*
  164.  * Types/orientation of gadboxes:
  165.  *
  166.  *  EB_HORIZONTAL  : the box may have several sons, which are
  167.  *                   ordered horizontal
  168.  *  EB_VERTICAL    : the box may have several sons, which are
  169.  *                   ordered vertical
  170.  *  EB_UNKNOWN     : the box may have only one son
  171.  *  EB_HORIZTABLE  : the box may have several sons, which may
  172.  *                   either be unknown, or vertical. All vertical
  173.  *                   sons must have the same number of sons,
  174.  *                   because the grandsons are ordered in a table.
  175.  *  EB_VERTITABLE  : the box may have several sons, which may
  176.  *                   either be unknown, or horizontal. All
  177.  *                   horizontal sons must have the same number of
  178.  *                   sons, because the grandsons are ordered in a
  179.  *                   table.
  180.  *  EB_SELECT      : the box may have several sons, which all lay
  181.  *                   at the same location.
  182.  */
  183.  
  184. #define EB_HORIZONTAL 0
  185. #define EB_VERTICAL   1
  186. #define EB_UNKNOWN    2
  187. #define EB_HORIZTABLE 3
  188. #define EB_VERTITABLE 4
  189. #define EB_SELECT     5
  190.  
  191. /*
  192.  * The aim of a gadgbox is given in the type field, possible values are:
  193.  *
  194.  *  EB_GADGET    : The box is to create a gadget. A pointer to the gadget
  195.  *                 has to be put into the "gad" field.
  196.  *  EB_DRAW      : The box contains a draing routine, which is specified by
  197.  *                 the "draw" field.
  198.  *  EB_WINDOW    : The box has a pointer to a new window structure in its
  199.  *                 "new" field.
  200.  *  EB_LATE      : The meaning of the box is not yet clear. Through rendering
  201.  *                 the "call" procedure is called with a pointer to the
  202.  *                 gadget in A0.
  203.  *  EB_RESPONSE  : The box returns its size and location back to the user,
  204.  *                 using a supplied EB_ResBox structure.
  205.  */
  206. #define EB_GADGET     0
  207. #define EB_DRAW       1
  208. #define EB_WINDOW     2
  209. #define EB_LATE       3
  210. #define EB_RESPONSE   4
  211.  
  212. typedef APTR EB_GBCreate;
  213.  
  214. /*
  215.  * EB_GadBox
  216.  *
  217.  * The primary element of a gadbox tree. This boxes may not be created by
  218.  * the programm, only by using functions from this or other EGB libraries.
  219.  * All boxes are discarded, after the calculation of the real gadgets.
  220.  *
  221.  *   .Prev,
  222.  *   .Next      : chaining of elements in the same level
  223.  *   .Father    : pointer to the upper element
  224.  *   .First,
  225.  *   .Last      : pointers to the first and last elements of the leafs of this
  226.  *                node
  227.  *   .Orient    : orientation
  228.  *   .MinWidth,
  229.  *   .MinHeight : minimal size of the box
  230.  *   .MaxWidth,
  231.  *   .MaxHeight : maximal size of the box
  232.  *   .X, .Y     : location, only valid after calculation
  233.  *   .Pri       : priority of the box
  234.  *                If there is more room in a row/collumn, than needed by the
  235.  *                elements, the additional space is spread over all elements
  236.  *                of the highest priority until their maximum is reached. Then
  237.  *                the elements with the next priority are stretched. This is
  238.  *                continued, until there is no more space, or all elements
  239.  *                are stretched to their maximum. In this case the additional
  240.  *                space is used to center the elements in the surrounding box.
  241.  *   .Con       : pointer to associated gadget context
  242.  *   .Type      : type of gadbox
  243.  *    .Gad      : pointer to a gadget, that is resized and rendered by
  244.  *                this box
  245.  *    .Draw     : drawing routine that is resized and located by this box
  246.  *    .New      : pointer to new window structure that is filled using the
  247.  *                informations of this box
  248.  *    .Call     : Routine that is called during calculation, when all the boxes
  249.  *                have their location and size. This routine may modify the
  250.  *                box itself, as all calculation is performed on its son, after
  251.  *                the call. This box type can be used to gain a list of gadgets,
  252.  *                whichs number depends on the size of the surrounding box.
  253.  *    .Res      : pointer to EB_ResInfo structure, to be filled with information
  254.  *                after calculation is done
  255.  *    .Selector : Routine that is called after calculation for an EB_select box
  256.  *                that carries a gadget. The routine is called once for each
  257.  *                son element with parameters, the parent box in A0, the number
  258.  *                of the sons in D0 and the render routine of the son in A1.
  259.  *    .UserData : free for user data, very handy for late or select boxes
  260.  *
  261.  */
  262. typedef struct EB_GadContextNode *EB_GadContext;
  263.  
  264. struct EB_GadBox{
  265.      EB_GadBoxPtr  Prev, Next, Father, First, Last;
  266.      UBYTE         Orient;
  267.      UBYTE         Pad1;
  268.      WORD          MinWidth, MaxWidth, MinHeight, MaxHeight;
  269.      WORD          X, Y;
  270.      BYTE          Pri;
  271.      UBYTE         Pad2;
  272.      EB_GadContext Con;
  273.      UBYTE         Type;
  274.      UBYTE          Pad3;
  275.      UWORD          Pad4;
  276.  
  277.      union {
  278.          EI_GadgetPtr         Gad;
  279.          IG_IntuiGfxPtr       Draw;
  280.          struct EI_NewWindow  *New;
  281.          EB_GBCreate          Call;
  282.          EB_ResBoxPtr         Res;
  283.            } Render;
  284.      APTR         Selector;
  285.      APTR         UserData;
  286. };
  287. /*
  288.  * Errormessages, supported by the .error field in the gadget context:
  289.  *
  290.  *  EB_OK                        : no error
  291.  *  EB_NOT_ENOUGH_MEMORY         : not enough memory for operation available
  292.  *  EB_UNKNOWN_WITH_MULTIPLE_SONS: a gadget with unknown location but several
  293.  *                                 sons was discoverd during calculation.
  294.  *  EB_STRING_GAD_NOT_FOUND      : A call to EB_LinkStringGadgets was done,
  295.  *                                 but the referenced gadgets could not be
  296.  *                                 found.
  297.  *  EB_ILLEGAL_SELECT            : A select box was discovered, which was no
  298.  *                                 gadget, or had no select call supported.
  299.  *  EB_UNKNOWN_FONT, EB_BAD_FONTS: The EB_CreateGadContext routine was called
  300.  *                                 with illegal fonts.
  301.  *  EB_NO_GAD_SOLUTION           : The library could not find a possible
  302.  *                                 solution for the given gadget box tree.
  303.  *  EB_UNMATCHING_TABLES         : A gadget table was discovered during
  304.  *                                 calculation, whichs sons had different
  305.  *                                 numbers of elements.
  306.  */
  307. #define EB_OK                        0;
  308. #define EB_NOT_ENOUGH_MEMORY         0x4000;
  309. #define EB_UNKNOWN_WITH_MULTIPLESONS 0x4001;
  310. #define EB_STRINGGAD_NOT_FOUND       0x4002;
  311. #define EB_ILLEGAL_SELECT            0x4003;
  312. #define EB_UNKNOWN_FONT              0x4004;
  313. #define EB_NO_WINDOW                 0x4005;
  314. #define EB_NO_GAD_SOLUTION           0x4006;
  315. #define EB_BAD_FONTS                 0x4007;
  316. #define EB_UNMATCHING_TABLES         0x4008;
  317.  
  318. #define EB_OWN_FONT  1
  319. #define EB_OWN_TFONT 2
  320.  
  321. /*
  322.  * EB_GadContext
  323.  *
  324.  * Structure that keeps track and information for a gadget box tree and the
  325.  * resulting list of gadgets and renderings. All box creating routines need
  326.  * this context as parameter. This structure is created and initialized using
  327.  * EB_CreateGadContext. When it is deleted using EB_DeleteGadContext, all
  328.  * asociated boxes, gadgets and rendering informations are also discarded,
  329.  * so make sure, not to delete the context, before you closed the window.
  330.  *
  331.  *  .Gadres      : permanent context, that keeps existing after the gadgets
  332.  *                 have been calculated.
  333.  *  .Helres      : temporary context, that is deleted, after the gadgets have
  334.  *                 been calculated.
  335.  *  .FHeight,
  336.  *  .FWidth      : the size of the capital "M" in the desired font.
  337.  *  .Font        : font for gadget elements, and additional rendering
  338.  *  .TFont       : font for textgadgets and information fields
  339.  *  .NewWin      : pointer to EI_NewWindow structure, which is valid after
  340.  *                 calculation.
  341.  *  .First       : pointer to first gadget in the created list
  342.  *  .Num         : number of gadgets in this list
  343.  *  .Color, Back : colors for 24 bit gadgets
  344.  *  .Error       : errorconditions that occur during operation
  345.  */
  346.  
  347. struct EB_GadContextNode {
  348.      EB_ContextPtr        Gadres, Helpres;
  349.      WORD                 FHeight, FWidth;
  350.      EG_EFontPtr          Font, TFont;
  351.      struct EI_NewWindow  *NewWin;
  352.      EI_GadgetPtr         First;
  353.      WORD                 Num;
  354.      UWORD                Pad1;
  355.      ULONG                Color, Back;
  356.      UBYTE                Flags;
  357.      UBYTE                Pad;
  358.      UWORD                Error;
  359. };
  360.  
  361. typedef char           *EB_StrArray[];
  362. typedef EB_StrArray    *EB_StrArrayPtr;
  363. typedef EB_StrArrayPtr  EB_StrArray2[];
  364. typedef EB_StrArray2   *EB_StrArray2Ptr;
  365.  
  366. typedef struct EB_SPropGadget *EB_SPropGadPtr;
  367.  
  368. struct EB_SPropGadget {
  369.      struct EI_MasterGadget Master;
  370.      EI_PropGadPtr          RealProp;
  371. };
  372.  
  373. /*
  374. *  EB_Max, EB_Min : extrem sizes for gadget boxes, serve as don't care
  375. */
  376.  
  377.  
  378.  
  379. #define EB_GAD_MAX   32767
  380. #define EB_GAD_MIN   0
  381.  
  382. /*
  383.  * Arrow locations in SuperPropGadgets
  384.  */
  385.  
  386. #define EB_DEC_UP_LEFT      1
  387. #define EB_DEC_BOTTOM_RIGHT 2
  388. #define EB_INC_UP_LEFT      4
  389. #define EB_INC_BOTTOM_RIGHT 8
  390.  
  391. #endif  /* EGS_EGSGADBOX_H */
  392.  
  393.  
  394.